﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;




public partial class SalesuserAccount : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {    

        if (Session["Authentication"] == null)
        {
            Response.Redirect("~/AdminLogin.aspx");
        }


      if (!IsPostBack)
        {
            gridData();
            
        }

    }


    public void gridData()
    {       

            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("SELECT orderID, orderedItems, customerName, customerMobile, customerAddress, customerCity, customerState, orderDate, STATUS FROM MAS_torderConfirmation", con);
            cmd.CommandType = CommandType.Text;
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            con.Open();
            sda.Fill(ds);
            con.Close();
            GridView2.DataSource = ds;
            GridView2.DataBind();

            


    }

    protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView2.EditIndex = e.NewEditIndex;
        gridData();
    }
    protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

        DropDownList status =
    (DropDownList)GridView2.Rows[e.RowIndex].FindControl("DropDownList1");
        //string orderID = (GridView2.Rows[e.RowIndex].FindControl("Label2").ToString());
        Label orderID = (Label)GridView2.Rows[e.RowIndex].FindControl("Label2");


        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString);
        string s = "UPDATE dbo.MAS_torderConfirmation SET STATUS= '" + status.SelectedValue.ToString() + "' WHERE orderID= " + orderID.Text;

        SqlCommand cmd = new SqlCommand("UPDATE dbo.MAS_torderConfirmation SET STATUS= '" + status.SelectedValue.ToString() + "' WHERE orderID= " + orderID.Text, con);
        cmd.CommandType = CommandType.Text;
        SqlDataAdapter sda = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        con.Open();
        sda.Fill(ds);
        con.Close();

        GridView2.EditIndex = -1;
        gridData();
    
    }
    protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView2.PageIndex = e.NewPageIndex;
        gridData();
    }
    protected void GridView2_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView2.EditIndex = -1;
        gridData();
    }
    
}